<?php if (!isset($galleryItem)): ?>
    <?php $galleryItem = new GalleryItem() ?>
<?php endif; ?>
<div class="clearfix">
    <label for="member_gallery_item_id">Profile Photo</label>        
    <div class="input">
        <div class="inline-block">
            <?php include_partial("gallery_item/potrait", array("user" => $user, 'height' => 50, "galleryItem" => $galleryItem)) ?>          
        </div>
        <div class="inline-block" style="padding-left: 10px;">
            <a id="pick-photo" href="javascript:;">Pick from our gallery</a>
        </div>
    </div>
</div>
<script type="text/javascript">
    $(document).ready(function(){         
        $("#pick-photo").live("click", function(){
            var url = '/gallery-item-pick-photo';
            $.get(url, {}, function(data){
                if(data == 'signin'){
                    requestLogin();
                }
                else{
                    openPopup(url, '395px', '280px');
                }
            }, 'html');
        });
        
        $(".gallery-item").live("click", function(){            
            var $this = $(this);            
            $('#member_gallery_item_id').val($this.attr('galleryitem'));            
            $('.profile-photo').attr('src', '/uploads/gallery/' + $this.attr('galleryitem') + '/normal-50.jpg');            
        });
    });
</script>